﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SchemaMonitor;
using SchemaMonitor.json;
using Framework;

public partial class usercontrols_UCComments : System.Web.UI.UserControl
{

	public void Display(List<CSoftComment> comments)
	{
        foreach (var i in comments)
        {
            var tr = new TableRow();
            tbl.Rows.Add(tr);
            if (tbl.Rows.Count % 2 == 0)
                tr.CssClass = "alt_row";

            var td = new TableCell();
            tr.Cells.Add(td);

            var lbl = new Label();
            lbl.Text = i.From.Name + ": <br/>";
            lbl.ToolTip = CUtilities.LongDateTime(i.CreatedTime) + "\r\nID=" + i.From.Id;
			lbl.Font.Bold = true;
			td.Controls.Add(lbl);
			td.Wrap = false;

			//lbl = new Label();
			//lbl.Text = CUtilities.LongDateTime(i.CreatedTime);
			//lbl.Font.Size = new FontUnit(FontSize.Smaller);
			//td.Controls.Add(lbl);


			if (i.LikeCount > 0)
			{
				lbl = new Label();
				lbl.Font.Bold = true;
				lbl.Text = "<br/>" + CUtilities.NameAndCount("likes", i.LikeCount);
				td.Controls.Add(lbl);

				if (i.HasLikes)
					lbl.ToolTip = CUtilities.ListToString(i.Likes);
			}

			td = new TableCell();
			tr.Cells.Add(td);


			lbl = new Label();
			lbl.Text = HttpUtility.HtmlEncode(i.Message).Replace("\r\n", "\n").Replace("\n", "<br/>").Replace("\t", "    ");
			td.Controls.Add(lbl);

			if (i.HasComments)
			{
				tr = new TableRow();
				tbl.Rows.Add(tr);

				td = new TableCell();
				tr.Cells.Add(td);
				td = new TableCell();
				tr.Cells.Add(td);

				UCComments(td).Display(i.Comments);
			}
		}
	}

	private usercontrols_UCComments UCComments(Control target)
	{
		Control ctrl = Page.LoadControl("~/usercontrols/uccomments.ascx");
		target.Controls.Add(ctrl);
		return (usercontrols_UCComments)ctrl;
	}
}